"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var ng_zorro_antd_1 = require("ng-zorro-antd");
var group_service_1 = require("../../group/group.service");
var api_1 = require("../../../../config/api");
var ViewComponent = /** @class */ (function () {
    function ViewComponent(routeInfo, displayService, fb, groupService, router, confirmServ, _message, localStorageService) {
        this.routeInfo = routeInfo;
        this.displayService = displayService;
        this.fb = fb;
        this.groupService = groupService;
        this.router = router;
        this.confirmServ = confirmServ;
        this._message = _message;
        this.localStorageService = localStorageService;
        this.fileList = [];
        this.picList = [];
        this.options = [];
        this.AliyunOssOutputUrl = api_1.AliyunOssOutputUrl;
        this.adSystemApiUrl = api_1.adSystemApiUrl;
        this.submitStatus = false;
        /* 商品弹窗 */
        this.goodsModalVisible = false;
        this.goodsList = [];
        this.groupList = [];
        this.currentClickGoods = {};
        this.checkedGoodsInfo = {};
        this.page = 1;
        this.pageSize = 5;
        this.status = '上架';
        this.loading = false;
        this.currentGoodsPrice = 0;
        this.comparePriceStatus = false;
        this.skuStatus = false;
        this.highPriceSkuId = null;
        this.ghostData = null;
        this.randomStatus = false;
        this.type = '';
        this.image = '';
        //活动弹窗
        this.activityModalVisible = false;
        this.activityList = [];
        this.activityLoading = false;
        this.currentClickActivity = {};
        this.checkedActivityInfo = {};
        this.self = this;
        //卡券弹窗
        this.couponPage = 1;
        this.couponPageSize = 5;
        this.couponModalVisible = false;
        this.couponList = [];
        this.couponLoading = false;
        this.currentClickCoupon = {};
        this.checkedCouponInfo = {};
        this.couponKeyWord = '';
        this.typeText = {
            1: { text: '普通拼团', color: 'rgb(299,112,23)' },
            2: { text: '拉新拼团', color: 'rgb(299,112,23)' },
            3: { text: '抽奖拼团', color: 'rgb(299,112,23)' },
            4: { text: '团长免单', color: 'rgb(299,112,23)' },
        };
    }
    ViewComponent.prototype.ngOnInit = function () {
        var _this = this;
        this.template_id = this.localStorageService.getNowApplet()['template_id'];
        this.routeInfo.params.subscribe(function (params) {
            if (_this.id != params.id) {
                _this.showcase_id = params.showcaseId;
                _this.id = params.id;
                _this.boothNumber = params.boothNumber;
                if (_this.displayService.list.length == 0) {
                    _this.getShowCaseList().then(function () {
                        _this.displayService.list.map(function (e, i) {
                            if (e['booth_number'] == _this.boothNumber) {
                                e['typeOpen'] = true;
                                _this.displayService.id = _this.id;
                                _this.displayService.name = e['name'];
                                _this.displayService.showCaseId = e['id'];
                                _this.displayService.boothNumber = _this.boothNumber;
                            }
                        });
                    });
                }
                _this.getShowCaseInfo(params.id);
                _this.displayService.initInfo(_this, _this.boothNumber);
            }
        });
    };
    ViewComponent.prototype.getFormControl = function (name) {
        return this.validateForm.controls[name];
    };
    //获取展位详情信息
    ViewComponent.prototype.getShowCaseInfo = function (id) {
        var _this = this;
        this.loadingData = true;
        this.displayService.getShowCaseDetailInfo(id).subscribe(function (res) {
            if (res.code === 2000) {
                _this.picList = [];
                _this.data = [];
                _this.name = res.data.name;
                _this.type = res.data.type;
                _this.url = res.data.url;
                //  a 产品 页面 卡券 活动
                // b 产品 页面 卡券 活动
                //c 图片
                if (_this.boothNumber === 'a' && _this.type === 'picture') {
                    _this.type = _this.options[0].value;
                }
                if (_this.boothNumber === 'c' && _this.type != 'picture') {
                    _this.type = _this.options[0].value;
                }
                if (_this.boothNumber === 'b' && _this.type === 'picture') {
                    _this.type = _this.options[0].value;
                }
                // if ((this.boothNumber === 'c' || this.boothNumber === 'b') && this.type === 'page') {
                //   this.type = this.options[0].value;
                // }
                if (res.data.image) {
                    _this.picList.push({ 'src': api_1.AliyunOssOutputUrl + "/" + res.data.image + "?update=" + Date.now() });
                }
                _this.name = res.data.name;
                _this.relationID = res.data.relationID;
                _this.sort = res.data.sort;
                // if ((this.type === 'picture' || this.type === 'activity') && res.data['activity']) {
                //   let activity = this.data = res.data['activity'];
                //   let goods = activity['activity_goods'][0];
                //   this.checkedActivityInfo = activity;
                //   this.checkedActivityInfo['type'] = this.typeText[goods['type']];
                //   this.checkedActivityInfo['goodsDetail'] = goods['goods'];
                //   this.loadingData = false;
                // } else if (res.data[this.type]) {
                //   this.data = res.data[this.type];
                //   this.loadingData = false;
                // } else {
                //   this.loadingData = false;
                // }
                if (_this.type === 'activity' && res.data['activity']) {
                    var activity = _this.data = res.data['activity'];
                    var goods = activity['activity_goods'][0];
                    _this.checkedActivityInfo = activity;
                    _this.checkedActivityInfo['type'] = _this.typeText[goods['type']];
                    _this.checkedActivityInfo['goodsDetail'] = goods['goods'];
                    _this.loadingData = false;
                }
                else if (res.data[_this.type]) {
                    _this.data = res.data[_this.type];
                    _this.loadingData = false;
                }
                else {
                    _this.loadingData = false;
                }
                console.log(_this.data);
            }
        });
    };
    ViewComponent.prototype.getShowCaseList = function () {
        var _this = this;
        return new Promise(function (resolve, reject) {
            _this.displayService.getShowCaseList(_this.template_id).subscribe(function (res) {
                if (res.code === 2000) {
                    _this.displayService.list = res.data.data;
                    var len_1 = _this.displayService.list.length;
                    _this.displayService.list.map(function (e, i) {
                        e['typeOpen'] = false;
                        e['addShow'] = false;
                        e['typeValue'] = '';
                        _this.displayService.getShowCaseDetailList(e['id']).subscribe(function (res1) {
                            if (res.code === 2000) {
                                len_1--;
                                var detailList = _this.displayService.list[i]['detailList'] = res1.data.data;
                                detailList.map(function (e, i) {
                                    e['edit'] = false;
                                });
                                if (len_1 === 0) {
                                    resolve();
                                }
                            }
                            ;
                        });
                    });
                }
            });
        });
    };
    ViewComponent.prototype.fileChange = function () {
        if (this.fileList.length == 0 && this.picList.length == 0) {
        }
        else {
        }
    };
    ViewComponent.prototype.editShowCaseDetail = function () {
        this.router.navigate(["member/display/edit/" + this.showcase_id + "/" + this.id + "/" + this.boothNumber]);
    };
    ViewComponent.prototype.delShowCaseDetail = function () {
        var _this = this;
        this.confirmServ.confirm({
            title: '温馨提示',
            content: '<b>您确定要删除这个橱窗吗</b>',
            onOk: function () {
                var matchArr = location.pathname.replace(/\//g, '.').split('.');
                var showCaseId = matchArr[matchArr.length - 3];
                var id = matchArr[matchArr.length - 2];
                var booth = location.pathname[location.pathname.length - 1];
                _this.displayService.list.forEach(function (e, i) {
                    if (e['booth_number'] === booth) {
                        _this.displayService.delShowCaseDetail(_this.id).subscribe(function (res) {
                            if (res.code === 2000) {
                                _this._message.create('success', '删除成功');
                                _this.displayService.getCaseDetailList(showCaseId, i + '').then(function (id) {
                                    if (id) {
                                        _this.displayService.id = id;
                                        _this.router.navigate(["member/display/" + showCaseId + "/" + id + "/" + booth]);
                                    }
                                    else {
                                        _this.router.navigate(["member/display/add/" + showCaseId + "/" + booth]);
                                    }
                                });
                            }
                            else {
                                _this._message.create('error', res.message);
                            }
                        });
                    }
                });
            },
            onCancel: function () {
            }
        });
    };
    //切换checked查看商品
    ViewComponent.prototype.toggleViewActivityGoods = function () {
        this.checkedActivityInfo['flexable'] = !this.checkedActivityInfo['flexable'];
    };
    ViewComponent = __decorate([
        core_1.Component({
            selector: 'app-view',
            templateUrl: './view.component.html',
            styleUrls: ['./view.component.scss'],
            providers: [ng_zorro_antd_1.NzMessageService, group_service_1.GroupService]
        })
    ], ViewComponent);
    return ViewComponent;
}());
exports.ViewComponent = ViewComponent;
